package com.bdqn.tour.dao.impl;

import com.bdqn.tour.dao.BaseDao;
import com.bdqn.tour.dao.HzyInfoVerifyDao;
import com.bdqn.tour.pojo.User;

import java.sql.SQLException;

public class HzyInfoVerifyDaoImpl extends BaseDao implements HzyInfoVerifyDao {
    @Override
    public boolean updateUser(User user) {
        this.conn = this.getConnection();
        String sql = "UPDATE user SET ipone=? WHERE id=?";
        try {
            return this.executeUpdate(sql, user.getIpone(), user.getId()) > 0;
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            this.closeAll(conn, psmt, rs);
        }
    }

    @Override
    public User validatePassword(String phone, String password) {
        conn = this.getConnection();
        User user = null;
        String sql = "SELECT * FROM user WHERE ipone = ? AND password = ?";
        try {
            rs = this.executeQuery(sql, phone, password);
            if (rs.next()) {
                user = new User();
                user.setId(rs.getInt(1));
                user.setUsername(rs.getString(2));
                user.setIpone(rs.getString(3));
                user.setPassword(rs.getString(4));
                user.setNickname(rs.getString(5));
                user.setEmail(rs.getString(6));
                user.setSex(rs.getString(7));
                user.setCareer(rs.getString(8));
                user.setQq(rs.getString(9));
                user.setStatus(rs.getString(10));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return user;
    }
}
